package com.kylin.common.core.entity;

import com.alibaba.fastjson2.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 通用数据实体类
 *
 * @author wuhao
 * @version 1.0 - 2019-02-13
 */
public abstract class DataEntity<T extends DataEntity<?>> extends Model<T> {

    /**状态类型： 正常 */
    public static final String STATUS_NORMAL = "0";
    /**状态类型： 禁用 */
    public static final String STATUS_DISABLE = "-1";

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "主键ID")
    private Long id;
    
    /** 创建者ID */
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty(hidden = true)
    protected Long createBy;

    /** 创建时间 */
    @OrderBy(sort = 2)
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    protected Date createTime;

    /** 更新者ID */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(hidden = true)
    protected Long updateBy;

    /** 更新时间 */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(hidden = true)
    protected Date updateTime;

    /** 状态 */
    @TableField(whereStrategy = FieldStrategy.NOT_EMPTY)
    @ApiModelProperty(value = "状态，0正常；-1禁用")
    protected String status;

    /** 逻辑删除值 */
    @TableLogic
    @JSONField(serialize=false)
    @ApiModelProperty(hidden = true)
    protected Integer deleteFlag;

    /**
     * 日期范围查询（大于等于）
     */
    @JSONField(serialize = false)
    @TableField(exist =  false )
    protected String beginTime;
    /**
     * 日期范围查询（小于等于）
     */
    @JSONField(serialize = false)
    @TableField(exist =  false )
    protected String endTime;

    
    /** 模糊检索 */
    @JSONField(serialize = false)
    @TableField(exist = false)
    @ApiModelProperty(hidden = true)
    protected String searchValue;


    /**
     * 搜索条件
     */
    @TableField(exist =  false)
    @JSONField(serialize=false)
    @ApiModelProperty(hidden = true)
    public QueryWrapper<T> queryWrapper = new QueryWrapper<>();

    /** sql 过滤条件 */
    @JSONField(serialize = false)
    @TableField(exist =  false )
    @ApiModelProperty(hidden = true)
    private String sqlFilter;

    /**
     * 插入之前操作
     * @version 1.0  by wuhao at 2019/6/24
     */
    public void perInsert(){
        if (StringUtils.isBlank(this.getStatus())) {
            this.setStatus("0");
        }
    }

    /**
     * 更新之前操作
     */
    public void perUpdate(){
    }

    public Integer getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Integer deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getStatus() {
        return this.status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public QueryWrapper<T> getQueryWrapper() {
        return queryWrapper;
    }

    public void setQueryWrapper(QueryWrapper<T> queryWrapper) {
        this.queryWrapper = queryWrapper;
    }

    public String getSqlFilter() {
        return sqlFilter;
    }

    public void setSqlFilter(String sqlFilter) {
        this.sqlFilter = sqlFilter;
    }

    public String getSearchValue() {
        return searchValue;
    }

    public void setSearchValue(String searchValue) {
        this.searchValue = searchValue;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }
}
